package com.eshop.modules.security.security.vo;

import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.function.Function;
import org.springframework.security.core.GrantedAuthority;
import java.util.Set;
import java.util.Date;
import java.sql.Timestamp;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import java.util.Collection;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.security.core.userdetails.UserDetails;

public class JwtUser implements UserDetails
{
    private final Long id;
    private final String username;
    private final String nickName;
    private final String sex;
    @JsonIgnore
    private final String password;
    private final String avatar;
    private final String email;
    private final String phone;
    private final String dept;
    private final String job;
    @JsonIgnore
    private final Collection<SimpleGrantedAuthority> authorities;
    private final boolean enabled;
    private Timestamp createTime;
    @JsonIgnore
    private final Date lastPasswordResetDate;
    
    @JsonIgnore
    public boolean isAccountNonExpired() {
        return true;
    }
    
    @JsonIgnore
    public boolean isAccountNonLocked() {
        return true;
    }
    
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return true;
    }
    
    @JsonIgnore
    public String getPassword() {
        return this.password;
    }
    
    public boolean isEnabled() {
        return this.enabled;
    }
    
    public Collection getRoles() {
        return this.authorities.stream().map((Function<? super SimpleGrantedAuthority, ?>)GrantedAuthority::getAuthority).collect(Collectors.toSet());
    }
    
    public Long getId() {
        return this.id;
    }
    
    public String getUsername() {
        return this.username;
    }
    
    public String getNickName() {
        return this.nickName;
    }
    
    public String getSex() {
        return this.sex;
    }
    
    public String getAvatar() {
        return this.avatar;
    }
    
    public String getEmail() {
        return this.email;
    }
    
    public String getPhone() {
        return this.phone;
    }
    
    public String getDept() {
        return this.dept;
    }
    
    public String getJob() {
        return this.job;
    }
    
    public Collection<SimpleGrantedAuthority> getAuthorities() {
        return this.authorities;
    }
    
    public Timestamp getCreateTime() {
        return this.createTime;
    }
    
    public Date getLastPasswordResetDate() {
        return this.lastPasswordResetDate;
    }
    
    public JwtUser(final Long id, final String username, final String nickName, final String sex, final String password, final String avatar, final String email, final String phone, final String dept, final String job, final Collection<SimpleGrantedAuthority> authorities, final boolean enabled, final Timestamp createTime, final Date lastPasswordResetDate) {
        this.id = id;
        this.username = username;
        this.nickName = nickName;
        this.sex = sex;
        this.password = password;
        this.avatar = avatar;
        this.email = email;
        this.phone = phone;
        this.dept = dept;
        this.job = job;
        this.authorities = authorities;
        this.enabled = enabled;
        this.createTime = createTime;
        this.lastPasswordResetDate = lastPasswordResetDate;
    }
}
